﻿<template>
  <div class="app-container">
    <div class="chart-title with-back">
      <div class="chart-left">
        <div>档案管理</div>
        <div class="backtrack">
          <el-button @click="comeBack">返回</el-button>
        </div>
      </div>
      <div class="chart-right">
        <el-button class="customize"
                   @click="submitData">提交</el-button>
      </div>
    </div>
    <div class="terminalList"
         v-for="(items, index) in chartData"
         :key="index">
      <div class="table-content">
        <div class="table-title">采购单{{ parseInt(index)+1 }}:&nbsp; {{ items.supplier_name }}</div>
        <el-table :data="items.list"
                  border
                  :header-cell-style="{background:'#F2F1F6',color:'#8B94BE'}"
                  style="width: 100%">
          <el-table-column :label="$t('terminal.name')"
                           align="center">
            <template slot-scope="scope">
              {{ scope.row.equipment_name }}
            </template>
          </el-table-column>
          <el-table-column :label="$t('public.type')"
                           align="center">
            <template slot-scope="scope">
              {{ scope.row.category_name }}
            </template>
          </el-table-column>
          <el-table-column label="品牌"
                           align="center">
            <template slot-scope="scope">
              {{ scope.row.brand_name }}
            </template>
          </el-table-column>
          <el-table-column :label="$t('terminal.attribute')"
                           align="center">
            <template slot-scope="scope">
              {{ scope.row.attribute }}
            </template>
          </el-table-column>
          <el-table-column :label="$t('goods.linkman')"
                           align="center">
            <template slot-scope="scope">
              {{ scope.row.linkman }}
            </template>
          </el-table-column>
          <el-table-column :label="$t('public.mobile')"
                           align="center">
            <template slot-scope="scope">
              {{ scope.row.linkman_mobile }}
            </template>
          </el-table-column>
          <el-table-column :label="$t('public.shippingAddress')"
                           align="center">
            <template slot-scope="scope">
              {{ scope.row.address }}
            </template>
          </el-table-column>
          <el-table-column :label="$t('public.number')"
                           align="center">
            <template slot-scope="scope">
              {{ scope.row.number }}
            </template>
          </el-table-column>
          <el-table-column :label="$t('public.price')"
                           align="center">
            <template slot-scope="scope">
              {{ scope.row.price }}
            </template>
          </el-table-column>
          <el-table-column label="价格小计"
                           align="center">
            <template slot-scope="scope">
              {{ scope.row.sum_price }}
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="table-banner"></div>
      <div class="statistics">
        <div class="statistics-left">
          备注信息：{{ items.remark }}
        </div>
        <div class="statistics-right">
          <div>设备： {{ items.number}}</div>
          <div>总计： {{ items.price }}</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script type="text/javascript">
import dropDownSelect from "@/views/select/dropDownSelect"; // 分页选择控件
export default {
  name: "PurchaseRequisition",
  components: {
    "drop-down-select": dropDownSelect
  },
  data() {
    return {
      chartData: undefined
    };
  },
  created() {
    this.ids = this.$route.query.ids
    this.getList();
  },
  methods: {
    getList() {
      this.listLoading = true;
      const path = {
        app: "equipment",
        api: "api_equipment_index_createEquipmentOrder",
        version: "1.0",
        data: {
          ids: this.ids ? this.ids : ""
        }
      }
      this.socketApi.sendSock(JSON.stringify(path), res => {
        if (res) {
          this.socketData(res);
        }
      });
    },
    comeBack() {
      this.$router.push({ path: '/terminal-data/terminal-application' })
    },
    submitData() {
      const listData = this.chartData;
      let data = [];
      listData.forEach(element => {
        data.push({ id: element.id, remark: element.remark })
      })
      const path = {
        app: "equipment",
        api: "api_equipment_index_orderSubmit",
        version: "1.0",
        data: data
      }
      this.socketApi.sendSock(JSON.stringify(path), res => {
        if (res) {
          this.socketData(res);
        }
      });
    },
    socketData(res) {
      if (res !== '{"type":"ping"}') {
        const resj = JSON.parse(res);
        if (resj.code === -1) {
          this.$message.error(resj.message);
        } else {
          if (resj.api === "api_equipment_index_createEquipmentOrder") {
            this.chartData = resj.data;
          } else if (resj.api === "api_equipment_index_orderSubmit") {
            this.comeBack();
          }
        }
      }
    }
  }
};
</script>
<style scoped>
.warehouse-info {
  display: flex;
  padding: 14px;
}
.action-bar {
  display: flex;
  justify-content: space-between;
  padding: 14px;
}
.warehouse-info div {
  flex: 1;
}
.action-right {
  display: flex;
}
.action-right div:not(:first-child) {
  margin-left: 14px;
}
.terminalList {
  background-color: #ffffff;
  border-radius: 4px;
  margin-bottom: 24px;
}
.terminalList .table-content {
  padding: 0 16px 16px 16px;
}
</style>
